package com.hhqk.service;

import java.util.Date;
import java.util.List;
import java.util.UUID;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.hhqk.mapper.DeptMapper;
import com.hhqk.model.Dept;


@Service //别忘了加注解，让Spring来管理
public class DeptService {
	
	@Autowired
	private DeptMapper deptMapper;

	public List<Dept> findAllDept() {
		
		return deptMapper.findAllDept();
	}
	/*
	 * 部门的新增保存，当controll传来的dept含有：deptName,parentId这个两个属性
	 * 还缺少：主键：dept_id，创建和更新时间 ，state 状态
	 */
	public void insert(Dept dept) {
		//UUID.randomUUID().toString()是用来生成uuid的
		dept.setDeptId(UUID.randomUUID().toString());
		
		//设置创建和更新时间
		dept.setCreateTime(new Date());
		dept.setUpdateTime(dept.getCreateTime());
		
		//设置状态，默认是启用的，所以是1
		dept.setState(1);
		
		deptMapper.insert(dept);
		
	}
	public Dept findDeptById(String deptId) {
		// TODO Auto-generated method stub
		return deptMapper.findDeptById(deptId);
	}
	public void update(Dept dept) {
		dept.setUpdateTime(new Date());
		deptMapper.update(dept);
		
	}
	public void deleteOne(String deptId) {
		deptMapper.deleteOne(deptId);
		
	}
	public void deleteBatch(String[] deptId) {
		deptMapper.deleteBatch(deptId);
		
	}

}
